﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YBApproval.IDAL;
using YBApproval.BLL;
using YBApproval.Model;

namespace YBApproval
{
    public partial class UCView : System.Web.UI.UserControl
    {
        private IInstanceValue _instValueDAL = DALFactory.GetDAL<IInstanceValue>();
        public string RecordId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            CreateControls();
        }

        private void CreateControls()
        {
            List<InstanceValue> list = _instValueDAL.GetValues(RecordId);
            TableRow row = null;
            bool isNewRow = true;
            foreach (InstanceValue item in list)
            {
                if (item.Field.IsWholeRow)
                {
                    row = new TableRow();
                    isNewRow = true;
                }
                else
                {
                    if (isNewRow)
                    {
                        row = new TableRow();
                        isNewRow = false;
                    }
                    else
                    {
                        isNewRow = true;
                    }
                }
                row.Cells.AddRange(ControlHelper.ForView(item));
                this.ContentTable.Rows.Add(row);
            }
        }

        public override void Dispose()
        {
            _instValueDAL.Dispose();
            base.Dispose();
        }
    }
}